package cn.lysoy.demo.controller;

import cn.lysoy.demo.domain.response.RespBean;
import cn.lysoy.demo.domain.vo.GoodsVo;
import cn.lysoy.demo.service.IGoodsService;
import cn.lysoy.demo.service.IUserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 类描述：商品
 *
 * @author: lysoy
 * @email: s2295938761@163.com
 * @date: 2022/02/23
 */
@RestController
@AllArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/goods")
public class GoodsController {
    private final IUserService userService;
    private final IGoodsService goodsService;

    /**
     * 方法功能描述：跳转到商品列表页，
     * 验证session,失败则返回登陆，
     * 成功则将信息存入model
     *
     * @author: lysoy
     * @email: s2295938761@163.com
     * @date: 2022/02/23
     * @return 商品列表页
     */
    @RequestMapping(value = "/toList", method = RequestMethod.GET)
    public RespBean toList(){
        List<GoodsVo> goodsList = goodsService.findGoodsVo();
        return RespBean.success(goodsList);
    }

    /**
     * 方法功能描述：跳转商品详情页面
     *
     * @author: lysoy
     * @email: s2295938761@163.com
     * @date: 2022/02/24
     * @param goodsId Goods.id
     * @return String
     */
    @RequestMapping(value = "/toDetail/{goodsId}", method = RequestMethod.GET)
    public RespBean toDetail(@PathVariable Long goodsId) {
        GoodsVo goodsVo = goodsService.findGoodsVoByGoodsId(goodsId);
        return RespBean.success(goodsVo);
    }
}
